#include<bits/stdc++.h>
using namespace std;
const int N=200010;
typedef long long LL;
int T;
LL n,ans,a[N],c[N];
bool f[N];
LL cnt()
{
    int pos1=0,pos0=0;
    LL nowans=0;
    for(int i=1;i<=n;i++)
    {
        if(f[i])
        {
            if(a[i]==a[pos1])
                nowans+=a[i];
            pos1=i;
        }
        else
        {
            if(a[i]==a[pos0])
                nowans+=a[i];
            pos0=i;
        }
    }
    return nowans;
}
void dfs(int t)
{
    if(t>n)
    {
        ans=max(ans,cnt());
        return;
    }
    f[t]=1;
    dfs(t+1);
    f[t]=0;
    dfs(t+1);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        ans=0;
        dfs(1);
        cout<<ans<<'\n';
    }
    return 0;
}
